home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
001
/
pibt40s2.arc
/
LTRIM.MOD
< prev
next >
Wrap
Text File
|
1987-05-18
|
6KB
|
82 lines
(*--------------------------------------------------------------------------*)
(* LTrim --- LTrim leading blanks from a string *)
(*--------------------------------------------------------------------------*)
FUNCTION LTrim( S : AnyStr ) : AnyStr;
(*--------------------------------------------------------------------------*)
(* *)
(* Function: LTrim *)
(* *)
(* Purpose: Trims leading blanks from a string *)
(* *)
(* Calling sequence: *)
(* *)
(* LTrimmed_S := TRIM( S ); *)
(* *)
(* S --- the string to be trimmed *)
(* LTrimmed_S --- the trimmed version of S *)
(* *)
(* Calls: None *)
(* *)
(* Remarks: *)
(* *)
(* Note that the original string itself is left untrimmed. *)
(* *)
(* A Pascal version of this routine could be written as: *)
(* *)
(* VAR *)
(* I: INTEGER; *)
(* L: INTEGER; *)
(* *)
(* BEGIN *)
(* *)
(* I := 1; *)
(* L := ORD( S[0] ); *)
(* *)
(* WHILE ( ( I <= L ) AND ( S[I] = ' ' ) ) DO *)
(* I := SUCC( I ); *)
(* *)
(* S[0] := CHR( MAX( L - I + 1 , 0 ) ); *)
(* *)
(* MOVE( S[I], S[1], ORD( S[0] ) ); *)
(* *)
(* LTrim := S; *)
(* *)
(* END; *)
(* *)
(*--------------------------------------------------------------------------*)
BEGIN (* LTrim *)
INLINE(
$1E/ { PUSH DS ; Save DS}
{;}
$8D/$BE/>S+1/ { LEA DI,[BP+>S+1] ; Offset of first source character}
$8A/$8E/>S/ { MOV CL,[BP+>S] ; Length of S}
$30/$ED/ { XOR CH,CH}
$E3/$1F/ { JCXZ LTrim2 ; If null string, no trimming}
$8C/$D0/ { MOV AX,SS ; Get stack segment ...}
$8E/$D8/ { MOV DS,AX ; for addressing source ...}
$8E/$C0/ { MOV ES,AX ; and destination strings}
$B0/$20/ { MOV AL,' ' ; Blank to AL}
{;}
$FC/ { CLD ; Forward search}
$F3/$AE/ { REPE SCASB ; Scan over blanks}
$74/$01/ { JE LTrim1 ; If CX=0, entire string is blank.}
$41/ { INC CX}
{;}
$88/$8E/$04/$01/ {LTrim1: MOV [BP+260],CL ; Set length in result}
$89/$FE/ { MOV SI,DI ; Offset of first non-blank}
$4E/ { DEC SI}
$8D/$BE/$05/$01/ { LEA DI,[BP+261] ; Offset of result}
$FC/ { CLD ; Forward move}
$F2/$A4/ { REP MOVSB ; Move trimmed result}
$E9/$04/$00/ { JMP Exit}
{;}
$88/$8E/$04/$01/ {LTrim2: MOV [BP+260],CL ; Set length=0 in result}
{;}
$1F); {Exit: POP DS ; Restore DS}
END (* LTrim *);